/*     */ package com.zimbra.cs.mailbox;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import java.util.Date;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AutoSendDraftTask
/*     */   extends ScheduledTask<Object>
/*     */ {
/*     */   private static final String TASK_NAME_PREFIX = "autoSendDraftTask";
/*     */   private static final String DRAFT_ID_PROP_NAME = "draftId";
/*     */   
/*     */   public String getName()
/*     */   {
/*  38 */     return "autoSendDraftTask" + getProperty("draftId");
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Void call()
/*     */     throws Exception
/*     */   {
/*  48 */     ZimbraLog.scheduler.debug("Running task %s", new Object[] { this });
/*  49 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
/*  50 */     if (mbox == null) {
/*  51 */       ZimbraLog.scheduler.error("Mailbox for id %s does not exist", new Object[] { Integer.valueOf(getMailboxId()) });
/*  52 */       return null;
/*     */     }
/*  54 */     Integer draftId = new Integer(getProperty("draftId"));
/*     */     Message msg;
/*     */     try {
/*  57 */       msg = (Message)mbox.getItemById(null, draftId.intValue(), MailItem.Type.MESSAGE);
/*     */     }
/*     */     catch (MailServiceException.NoSuchItemException e) {
/*  60 */       ZimbraLog.scheduler.debug("Draft message with id %s no longer exists in mailbox", new Object[] { draftId });
/*  61 */       return null;
/*     */     }
/*  63 */     if (msg.getDraftAutoSendTime() == 0L) {
/*  64 */       ZimbraLog.scheduler.warn("Message with id %s is not a Draft scheduled to be auto-sent", new Object[] { draftId });
/*  65 */       return null;
/*     */     }
/*  67 */     if ((msg.isTagged(Flag.FlagInfo.DELETED)) || (msg.inTrash())) {
/*  68 */       ZimbraLog.scheduler.debug("Draft with id %s is deleted", new Object[] { draftId });
/*  69 */       return null;
/*     */     }
/*     */     
/*  72 */     MailSender mailSender = mbox.getMailSender();
/*  73 */     mailSender.setOriginalMessageId(StringUtil.isNullOrEmpty(msg.getDraftOrigId()) ? null : new ItemId(msg.getDraftOrigId(), mbox.getAccountId()));
/*  74 */     mailSender.setReplyType(StringUtil.isNullOrEmpty(msg.getDraftReplyType()) ? null : msg.getDraftReplyType());
/*  75 */     mailSender.setIdentity(StringUtil.isNullOrEmpty(msg.getDraftIdentityId()) ? null : mbox.getAccount().getIdentityById(msg.getDraftIdentityId()));
/*  76 */     mailSender.sendMimeMessage(new OperationContext(mbox), mbox, msg.getMimeMessage());
/*     */     
/*  78 */     mbox.delete(null, draftId.intValue(), MailItem.Type.MESSAGE);
/*  79 */     return null;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void cancelTask(int draftId, int mailboxId)
/*     */     throws ServiceException
/*     */   {
/*  90 */     ScheduledTaskManager.cancel(AutoSendDraftTask.class.getName(), "autoSendDraftTask" + Integer.toString(draftId), mailboxId, true);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void scheduleTask(int draftId, int mailboxId, long autoSendTime)
/*     */     throws ServiceException
/*     */   {
/* 106 */     AutoSendDraftTask autoSendDraftTask = new AutoSendDraftTask();
/* 107 */     autoSendDraftTask.setMailboxId(mailboxId);
/* 108 */     autoSendDraftTask.setExecTime(new Date(autoSendTime));
/* 109 */     autoSendDraftTask.setProperty("draftId", Integer.toString(draftId));
/* 110 */     ScheduledTaskManager.schedule(autoSendDraftTask);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/AutoSendDraftTask.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */